1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.InfoBar; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Button; 32 private import gtk.Widget; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 private import std.algorithm; 36 37 38 /** 39 * `GtkInfoBar` can be show messages to the user without a dialog. 40 * 41 *  42 * 43 * It is often temporarily shown at the top or bottom of a document. 44 * In contrast to [class@Gtk.Dialog], which has an action area at the 45 * bottom, `GtkInfoBar` has an action area at the side. 46 * 47 * The API of `GtkInfoBar` is very similar to `GtkDialog`, allowing you 48 * to add buttons to the action area with [method@Gtk.InfoBar.add_button] 49 * or [ctor@Gtk.InfoBar.new_with_buttons]. The sensitivity of action widgets 50 * can be controlled with [method@Gtk.InfoBar.set_response_sensitive]. 51 * 52 * To add widgets to the main content area of a `GtkInfoBar`, use 53 * [method@Gtk.InfoBar.add_child]. 54 * 55 * Similar to [class@Gtk.MessageDialog], the contents of a `GtkInfoBar` 56 * can by classified as error message, warning, informational message, etc, 57 * by using [method@Gtk.InfoBar.set_message_type]. GTK may use the message 58 * type to determine how the message is displayed. 59 * 60 * A simple example for using a `GtkInfoBar`: 61 * ```c 62 * GtkWidget *message_label; 63 * GtkWidget *widget; 64 * GtkWidget *grid; 65 * GtkInfoBar *bar; 66 * 67 * // set up info bar 68 * widget = gtk_info_bar_new (); 69 * bar = GTK_INFO_BAR (widget); 70 * grid = gtk_grid_new (); 71 * 72 * message_label = gtk_label_new (""); 73 * gtk_info_bar_add_child (bar, message_label); 74 * gtk_info_bar_add_button (bar, 75 * _("_OK"), 76 * GTK_RESPONSE_OK); 77 * g_signal_connect (bar, 78 * "response", 79 * G_CALLBACK (gtk_widget_hide), 80 * NULL); 81 * gtk_grid_attach (GTK_GRID (grid), 82 * widget, 83 * 0, 2, 1, 1); 84 * 85 * // ... 86 * 87 * // show an error message 88 * gtk_label_set_text (GTK_LABEL (message_label), "An error occurred!"); 89 * gtk_info_bar_set_message_type (bar, GTK_MESSAGE_ERROR); 90 * gtk_widget_show (bar); 91 * ``` 92 * 93 * # GtkInfoBar as GtkBuildable 94 * 95 * `GtkInfoBar` supports a custom `<action-widgets>` element, which can contain 96 * multiple `<action-widget>` elements. The “response” attribute specifies a 97 * numeric response, and the content of the element is the id of widget 98 * (which should be a child of the dialogs @action_area). 99 * 100 * `GtkInfoBar` supports adding action widgets by specifying “action” as 101 * the “type” attribute of a `<child>` element. The widget will be added 102 * either to the action area. The response id has to be associated 103 * with the action widget using the `<action-widgets>` element. 104 * 105 * # CSS nodes 106 * 107 * `GtkInfoBar` has a single CSS node with name infobar. The node may get 108 * one of the style classes .info, .warning, .error or .question, depending 109 * on the message type. 110 * If the info bar shows a close button, that button will have the .close 111 * style class applied. 112 */ 113 public class InfoBar : Widget 114 { 115 /** the main Gtk struct */ 116 protected GtkInfoBar* gtkInfoBar; 117 118 /** Get the main Gtk struct */ 119 public GtkInfoBar* getInfoBarStruct(bool transferOwnership = false) 120 { 121 if (transferOwnership) 122 ownedRef = false; 123 return gtkInfoBar; 124 } 125 126 /** the main Gtk struct as a void* */ 127 protected override void* getStruct() 128 { 129 return cast(void*)gtkInfoBar; 130 } 131 132 /** 133 * Sets our main struct and passes it to the parent class. 134 */ 135 public this (GtkInfoBar* gtkInfoBar, bool ownedRef = false) 136 { 137 this.gtkInfoBar = gtkInfoBar; 138 super(cast(GtkWidget*)gtkInfoBar, ownedRef); 139 } 140 141 142 /** */ 143 public static GType getType() 144 { 145 return gtk_info_bar_get_type(); 146 } 147 148 /** 149 * Creates a new `GtkInfoBar` object. 150 * 151 * Returns: a new `GtkInfoBar` object 152 * 153 * Throws: ConstructionException GTK+ fails to create the object. 154 */ 155 public this() 156 { 157 auto __p = gtk_info_bar_new(); 158 159 if(__p is null) 160 { 161 throw new ConstructionException("null returned by new"); 162 } 163 164 this(cast(GtkInfoBar*) __p); 165 } 166 167 /** 168 * Add an activatable widget to the action area of a `GtkInfoBar`. 169 * 170 * This also connects a signal handler that will emit the 171 * [signal@Gtk.InfoBar::response] signal on the message area 172 * when the widget is activated. The widget is appended to the 173 * end of the message areas action area. 174 * 175 * Params: 176 * child = an activatable widget 177 * responseId = response ID for @child 178 */ 179 public void addActionWidget(Widget child, int responseId) 180 { 181 gtk_info_bar_add_action_widget(gtkInfoBar, (child is null) ? null : child.getWidgetStruct(), responseId); 182 } 183 184 /** 185 * Adds a button with the given text. 186 * 187 * Clicking the button will emit the [signal@Gtk.InfoBar::response] 188 * signal with the given response_id. The button is appended to the 189 * end of the info bars's action area. The button widget is returned, 190 * but usually you don't need it. 191 * 192 * Params: 193 * buttonText = text of button 194 * responseId = response ID for the button 195 * 196 * Returns: the `GtkButton` widget 197 * that was added 198 */ 199 public Button addButton(string buttonText, int responseId) 200 { 201 auto __p = gtk_info_bar_add_button(gtkInfoBar, Str.toStringz(buttonText), responseId); 202 203 if(__p is null) 204 { 205 return null; 206 } 207 208 return ObjectG.getDObject!(Button)(cast(GtkButton*) __p); 209 } 210 211 /** 212 * Adds a widget to the content area of the info bar. 213 * 214 * Params: 215 * widget = the child to be added 216 */ 217 public void addChild(Widget widget) 218 { 219 gtk_info_bar_add_child(gtkInfoBar, (widget is null) ? null : widget.getWidgetStruct()); 220 } 221 222 /** 223 * Returns the message type of the message area. 224 * 225 * Returns: the message type of the message area. 226 */ 227 public GtkMessageType getMessageType() 228 { 229 return gtk_info_bar_get_message_type(gtkInfoBar); 230 } 231 232 /** 233 * Returns whether the info bar is currently revealed. 234 * 235 * Returns: the current value of the [property@Gtk.InfoBar:revealed] property 236 */ 237 public bool getRevealed() 238 { 239 return gtk_info_bar_get_revealed(gtkInfoBar) != 0; 240 } 241 242 /** 243 * Returns whether the widget will display a standard close button. 244 * 245 * Returns: %TRUE if the widget displays standard close button 246 */ 247 public bool getShowCloseButton() 248 { 249 return gtk_info_bar_get_show_close_button(gtkInfoBar) != 0; 250 } 251 252 /** 253 * Removes a widget from the action area of @info_bar. 254 * 255 * The widget must have been put there by a call to 256 * [method@Gtk.InfoBar.add_action_widget] or [method@Gtk.InfoBar.add_button]. 257 * 258 * Params: 259 * widget = an action widget to remove 260 */ 261 public void removeActionWidget(Widget widget) 262 { 263 gtk_info_bar_remove_action_widget(gtkInfoBar, (widget is null) ? null : widget.getWidgetStruct()); 264 } 265 266 /** 267 * Removes a widget from the content area of the info bar. 268 * 269 * Params: 270 * widget = a child that has been added to the content area 271 */ 272 public void removeChild(Widget widget) 273 { 274 gtk_info_bar_remove_child(gtkInfoBar, (widget is null) ? null : widget.getWidgetStruct()); 275 } 276 277 /** 278 * Emits the “response” signal with the given @response_id. 279 * 280 * Params: 281 * responseId = a response ID 282 */ 283 public void response(int responseId) 284 { 285 gtk_info_bar_response(gtkInfoBar, responseId); 286 } 287 288 /** 289 * Sets the last widget in the info bar’s action area with 290 * the given response_id as the default widget for the dialog. 291 * 292 * Pressing “Enter” normally activates the default widget. 293 * 294 * Note that this function currently requires @info_bar to 295 * be added to a widget hierarchy. 296 * 297 * Params: 298 * responseId = a response ID 299 */ 300 public void setDefaultResponse(int responseId) 301 { 302 gtk_info_bar_set_default_response(gtkInfoBar, responseId); 303 } 304 305 /** 306 * Sets the message type of the message area. 307 * 308 * GTK uses this type to determine how the message is displayed. 309 * 310 * Params: 311 * messageType = a `GtkMessageType` 312 */ 313 public void setMessageType(GtkMessageType messageType) 314 { 315 gtk_info_bar_set_message_type(gtkInfoBar, messageType); 316 } 317 318 /** 319 * Sets the sensitivity of action widgets for @response_id. 320 * 321 * Calls `gtk_widget_set_sensitive (widget, setting)` for each 322 * widget in the info bars’s action area with the given @response_id. 323 * A convenient way to sensitize/desensitize buttons. 324 * 325 * Params: 326 * responseId = a response ID 327 * setting = TRUE for sensitive 328 */ 329 public void setResponseSensitive(int responseId, bool setting) 330 { 331 gtk_info_bar_set_response_sensitive(gtkInfoBar, responseId, setting); 332 } 333 334 /** 335 * Sets whether the `GtkInfoBar` is revealed. 336 * 337 * Changing this will make @info_bar reveal or conceal 338 * itself via a sliding transition. 339 * 340 * Note: this does not show or hide @info_bar in the 341 * [property@Gtk.Widget:visible] sense, so revealing has no effect 342 * if [property@Gtk.Widget:visible] is %FALSE. 343 * 344 * Params: 345 * revealed = The new value of the property 346 */ 347 public void setRevealed(bool revealed) 348 { 349 gtk_info_bar_set_revealed(gtkInfoBar, revealed); 350 } 351 352 /** 353 * If true, a standard close button is shown. 354 * 355 * When clicked it emits the response %GTK_RESPONSE_CLOSE. 356 * 357 * Params: 358 * setting = %TRUE to include a close button 359 */ 360 public void setShowCloseButton(bool setting) 361 { 362 gtk_info_bar_set_show_close_button(gtkInfoBar, setting); 363 } 364 365 /** 366 * Gets emitted when the user uses a keybinding to dismiss the info bar. 367 * 368 * The ::close signal is a [keybinding signal](class.SignalAction.html). 369 * 370 * The default binding for this signal is the Escape key. 371 */ 372 gulong addOnClose(void delegate(InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 373 { 374 return Signals.connect(this, "close", dlg, connectFlags ^ ConnectFlags.SWAPPED); 375 } 376 377 /** 378 * Emitted when an action widget is clicked. 379 * 380 * The signal is also emitted when the application programmer 381 * calls [method@Gtk.InfoBar.response]. The @response_id depends 382 * on which action widget was clicked. 383 * 384 * Params: 385 * responseId = the response ID 386 */ 387 gulong addOnResponse(void delegate(int, InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 388 { 389 return Signals.connect(this, "response", dlg, connectFlags ^ ConnectFlags.SWAPPED); 390 } 391 }